
{***********************************************************}
{                                                           }
{      Informix Data Access Components                      }
{                                                           }
{      Registration unit                                    }
{                                                           }
{      Copyright (c) 2001-2008 Luxena Software Company      }
{      http://www.luxena.com                                }
{      e-mail: support@luxena.com                           }
{                                                           }
{***********************************************************}

unit IfxReg;

{$I lx.inc}

interface

uses
{$IFDEF D6}
  DesignIntf, DesignEditors,
{$ELSE}
  DsgnIntf,
{$ENDIF}
  SysUtils, Classes, DB, DBReg, FldLinks, DsnDBCst, IfxTable;

type

{ TIfxConnectionParamsEditor }

  TIfxConnectionParamsEditor = class(TComponentEditor)
  public
    procedure ExecuteVerb(Index: Integer); override;
    function GetVerb(Index: Integer): string; override;
    function GetVerbCount: Integer; override;
  end;


{ TIfxConnectionParamsProperty }

  TIfxConnectionParamsProperty = class(TClassProperty)
  public
    function GetAttributes: TPropertyAttributes; override;
    procedure Edit; override;
  end;


{ TIfxTableFieldLinkProperty }

  TIfxTableFieldLinkProperty = class(TFieldLinkProperty)
  private
    FTable: TIfxTable;
  protected
    procedure GetFieldNamesForIndex(List: TStrings); override;
    function GetIndexDefs: TIndexDefs; override;
    function GetIndexFieldNames: string; override;
    function GetIndexName: string; override;
    function GetMasterFields: string; override;
    procedure SetIndexFieldNames(const Value: string); override;
    procedure SetIndexName(const Value: string); override;
    procedure SetMasterFields(const Value: string); override;
  public
    property IndexDefs: TIndexDefs read GetIndexDefs;
    property IndexFieldNames: string read GetIndexFieldNames write SetIndexFieldNames;
    property IndexName: string read GetIndexName write SetIndexName;
    property MasterFields: string read GetMasterFields write SetMasterFields;
    procedure Edit; override;
  end;


{ TIfxTableNameProperty }

  TIfxTableNameProperty = class(TDBStringProperty)
  public
    procedure GetValueList(List: TStrings); override;
  end;


{ TIfxStoredProcNameProperty }

  TIfxStoredProcNameProperty = class(TDBStringProperty)
  public
    procedure GetValueList(List: TStrings); override;
  end;


{ TIfxUpdateSQLEditor }

  TIfxUpdateSQLEditor = class(TComponentEditor)
  public
    procedure ExecuteVerb(Index: Integer); override;
    function GetVerb(Index: Integer): string; override;
    function GetVerbCount: Integer; override;
  end;


{ TIfxCompositMonitorEditor }

  TIfxCompositMonitorEditor = class(TComponentEditor)
  public
    procedure ExecuteVerb(Index: Integer); override;
    function GetVerb(Index: Integer): string; override;
    function GetVerbCount: Integer; override;
  end;


procedure Register;


implementation

{$R *.res}

uses
  ColnEdit, Ifx, IfxConnection, IfxSQLProcessor, IfxFieldTypes, IfxQuery,
  IfxStoredProc, IfxDataSet, IfxUpdateSQL, IfxSQL, IfxMonitor, IfxFileMonitor,
  IfxVisualMonitor, IfxNativeFields, IfxConParamForm, IfxUpdateSQLForm;

const
  SPalIDAC = 'IDAC';

resourcestring
  SEditParams = 'Edit Connection Params...';
  SUpdateSQLEditor = '&IfxUpdateSQL Editor...';
  SCompositMonitorEditor = 'Edit Items...';


{ TIfxConnectionParamsEditor }

procedure TIfxConnectionParamsEditor.ExecuteVerb(Index: Integer);
var
  I: Integer;
begin
  I := inherited GetVerbCount;
  if Index < I then
    inherited else
  if Index - I = 0 then
    if TIfxFormConParams.Edit(Component as TIfxConnection) then
      Designer.Modified;
end;

function TIfxConnectionParamsEditor.GetVerb(Index: Integer): string;
var
  I: Integer;
begin
  I := inherited GetVerbCount;
  if Index < I then
    Result := inherited GetVerb(Index) else
  if Index - I = 0 then
    Result := SEditParams;
end;

function TIfxConnectionParamsEditor.GetVerbCount: Integer;
begin
  Result := inherited GetVerbCount + 1;
end;


{ TIfxConnectionParamsProperty }

function TIfxConnectionParamsProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paDialog, paReadOnly];
end;

procedure TIfxConnectionParamsProperty.Edit;
begin
  if TIfxFormConParams.Edit(GetComponent(0) as TIfxConnection) then
    Modified;
end;


{ TIfxTableFieldLinkProperty }

procedure TIfxTableFieldLinkProperty.GetFieldNamesForIndex(List: TStrings);
var
  I: Integer;
begin
  for I := 0 to FTable.IndexFieldCount - 1 do
    List.Add(FTable.IndexFields[I].FieldName);
end;

function TIfxTableFieldLinkProperty.GetIndexDefs: TIndexDefs;
begin
  Result := FTable.IndexDefs;
end;

function TIfxTableFieldLinkProperty.GetIndexFieldNames: string;
begin
  Result := FTable.IndexFieldNames;
end;

function TIfxTableFieldLinkProperty.GetIndexName: string;
begin
  Result := FTable.IndexName;
end;

function TIfxTableFieldLinkProperty.GetMasterFields: string;
begin
  Result := FTable.MasterFields;
end;

procedure TIfxTableFieldLinkProperty.SetIndexFieldNames(const Value: string);
begin
  FTable.IndexFieldNames := Value;
end;

procedure TIfxTableFieldLinkProperty.SetIndexName(const Value: string);
begin
  if Value = SPrimary then
    FTable.IndexName := '' else
    FTable.IndexName := Value;
end;

procedure TIfxTableFieldLinkProperty.SetMasterFields(const Value: string);
begin
  FTable.MasterFields := Value;
end;

procedure TIfxTableFieldLinkProperty.Edit;
var
  Table: TIfxTable;
begin
  Table := DataSet as TIfxTable;
  FTable := TIfxTable.Create(nil);
  try
    FTable.Connection := Table.Connection;
    FTable.TableName := Table.TableName;
    if Table.IndexFieldNames <> '' then
      FTable.IndexFieldNames := Table.IndexFieldNames else
      FTable.IndexName := Table.IndexName;
    FTable.MasterFields := Table.MasterFields;
    FTable.Open;

    inherited;

    if Changed then
    begin
      Table.MasterFields := FTable.MasterFields;
      if FTable.IndexFieldNames <> '' then
        Table.IndexFieldNames := FTable.IndexFieldNames else
        Table.IndexName := FTable.IndexName;
    end;
  finally
    FTable.Free;
  end;
end;


{ TIfxTableNameProperty }

procedure TIfxTableNameProperty.GetValueList(List: TStrings);
begin
  with GetComponent(0) as TIfxTable do
    if Connection <> nil then
      try
        Connection.GetTableNames(List);
      except
      end;
end;


{ TIfxStoredProcNameProperty }

procedure TIfxStoredProcNameProperty.GetValueList(List: TStrings);
begin
  with GetComponent(0) as TIfxStoredProc do
    if Connection <> nil then
      try
        Connection.GetStoredProcNames(List);
      except
      end;
end;


{ TIfxUpdateSQLEditor }

procedure TIfxUpdateSQLEditor.ExecuteVerb(Index: Integer);
var
  I: Integer;
begin
  I := inherited GetVerbCount;
  if Index < I then
    inherited else
  if Index - I = 0 then
    if TIfxFormUpdateSQL.Edit(Component as TIfxUpdateSQL) then
      Designer.Modified;
end;

function TIfxUpdateSQLEditor.GetVerb(Index: Integer): string;
var
  I: Integer;
begin
  I := inherited GetVerbCount;
  if Index < I then
    Result := inherited GetVerb(Index) else
  if Index - I = 0 then
    Result := SUpdateSQLEditor;
end;

function TIfxUpdateSQLEditor.GetVerbCount: Integer;
begin
  Result := inherited GetVerbCount + 1;
end;


{ TIfxCompositMonitorEditor }

procedure TIfxCompositMonitorEditor.ExecuteVerb(Index: Integer);
var
  I: Integer;
begin
  I := inherited GetVerbCount;
  if Index < I then
    inherited else
  if Index - I = 0 then
    ShowCollectionEditor(Designer, Component, (Component as
      TIfxCompositMonitor).Items, 'Monitors');
end;

function TIfxCompositMonitorEditor.GetVerb(Index: Integer): string;
var
  I: Integer;
begin
  I := inherited GetVerbCount;
  if Index < I then
    Result := inherited GetVerb(Index) else
  if Index - I = 0 then
    Result := SCompositMonitorEditor;
end;

function TIfxCompositMonitorEditor.GetVerbCount: Integer;
begin
  Result := inherited GetVerbCount + 1;
end;


{ Registration }

procedure Register;
begin
  RegisterComponents(SPalIDAC, [TIfxConnection, TIfxSQLProcessor, TIfxFieldTypes,
    TIfxTable, TIfxQuery, TIfxStoredProc, TIfxDataSet, TIfxUpdateSQL, TIfxSQL,
    TIfxCompositMonitor, TIfxFileMonitor, TIfxVisualMonitor, TIDACEvents]);

  RegisterPropertyEditor(TypeInfo(TStrings), TIfxConnection, 'Params',
    TIfxConnectionParamsProperty);

  RegisterPropertyEditor(TypeInfo(string), TIfxTable, 'TableName',
    TIfxTableNameProperty);
  RegisterPropertyEditor(TypeInfo(string), TIfxTable, 'IndexName',
    TIndexNameProperty);
  RegisterPropertyEditor(TypeInfo(string), TIfxTable, 'IndexFieldNames',
    TIndexFieldNamesProperty);
  RegisterPropertyEditor(TypeInfo(string), TIfxTable, 'MasterFields',
    TIfxTableFieldLinkProperty);
    
  RegisterPropertyEditor(TypeInfo(string), TIfxStoredProc, 'StoredProcName',
    TIfxStoredProcNameProperty);
    
  RegisterFields([TIfxCharField, TIfxSmallIntField, TIfxIntegerField,
    TIfxFloatField, TIfxSmallFloatField, TIfxDecimalField, TIfxSerialField,
    TIfxDateField, TIfxMoneyField, TIfxDateTimeField, TIfxVarCharField,
    TIfxIntervalField, TIfxNCharField, TIfxNVarCharField, TIfxInt8Field,
    TIfxBlobField, TIfxClobField, TIfxLVarCharField]);

  RegisterComponentEditor(TIfxConnection, TIfxConnectionParamsEditor);
  RegisterComponentEditor(TIfxUpdateSQL, TIfxUpdateSQLEditor);
  RegisterComponentEditor(TIfxCompositMonitor, TIfxCompositMonitorEditor);
end;


end.